home *** CD-ROM | disk | FTP | other *** search
- /* File: LibraryManager.h
-
- Contains: Minimal declarations you need to use the Shared Library Manager.
-
- Copyright: © 1991-1992 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef __LIBRARYMANAGER__
- #define __LIBRARYMANAGER__
-
- #ifndef __STDDEF__
- #include <StdDef.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- /*******************************************************************************
- ** System-wide Defines
- ********************************************************************************/
-
- #ifndef qDebug
- #define qDebug 1
- #endif
-
- #define UNIX 0
- #define MACOS 1
- #define KERNELSPACE 0
-
- /*******************************************************************************
- ** Error Constants
- ********************************************************************************/
-
- const OSErr kNoError = 0;
- const OSErr kInProgress = 1;
-
- const OSErr kNotFound = -3120; // class wasn't found
- const OSErr kNoParent = -3121; // class doesn't have a shared parent
- const OSErr kParentNotFound = -3122; // shared parent of class could not be found
- const OSErr kNotRelated = -3123; // the classes are not related
- const OSErr kInvalidObject = -3124; // not a valid object
-
- const OSErr kPoolCorrupted = -3125;
- const OSErr kOutOfMemory = -3126;
-
- const OSErr kCodeNotLoaded = -3127;
- const OSErr kCouldNotLoadCode = -3128;
-
- const OSErr kFilePreflighted = -3129; // can't close library file because it is preflighted
- const OSErr kFileNotPreflighted = -3130; // failed because library file is not preflighted
- const OSErr kFileNotFound = -3131;
-
- const OSErr kLibraryManagerNotLoaded = -3132;
-
- const OSErr kDuplicateFound = -3134; // duplicate found is collection
- const OSErr kSeedChanged = -3135;
-
- const OSErr kInternalError = -3135;
- const OSErr kUnconstructedObject = -3136;
-
- const OSErr kNotSupported = -3167; // matches the XTI error code
-
- /**********************************************************************
- ** Forward class declarations
- ***********************************************************************/
-
- #ifdef __cplusplus
-
- class TDynamic;
- class TLibraryManager;
- class TClassID;
-
- class TLibraryFile;
- class TFormattedStream;
- class TMemoryPool;
- class TStandardPool;
- class TLibraryFile;
- class TConfiguration;
- class TClassInfo;
- class TException;
- class TSimpleList;
- #else
-
- typedef void TDynamic;
- typedef void TLibraryManager;
- typedef char* TClassID;
-
- typedef void TStandardPool;
-
- #endif __cplusplus
-
- /*******************************************************************************
- ** Enums for Memory types
- ********************************************************************************/
-
- enum ZoneType
- {
- kSystemZone = 1, kKernelZone, kApplicZone,
- kCurrentZone, kTempZone
- };
-
- enum MemoryType
- {
- kNormalMemory = 1, kHoldMemory, kLockMemory, kLockMemoryContiguous
- };
-
- /**********************************************************************
- ** Some inlines. Prototypes are also given in Global Routines section
- ** to make them easier to read.
- ***********************************************************************/
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- extern TLibraryManager* __gLibraryManager;
-
- #ifdef __cplusplus
- inline TLibraryManager* GetLocalLibraryManager()
- {
- return __gLibraryManager; // developers, never access __gLibraryManager directly!
- };
- #else
- #define GetLocalLibraryManager() (__gLibraryManager)
- #endif
-
- /*******************************************************************************
- ** Some "C" Global routines
- **
- ** InitLibraryManager initializes a client to use the LibraryManager. All clients
- ** must make this call except for LibraryManager libraries. CleanupLibraryManager
- ** should be called when the client is done using the LibraryManager.
- **
- ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
- ** returns NULL then InitLibraryManager failed.
- ********************************************************************************/
-
- #ifdef __cplusplus
- OSErr InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
- MemoryType = kNormalMemory);
- #else
- OSErr InitLibraryManager(size_t poolsize, short zoneType, short memType);
- #endif
-
- void CleanupLibraryManager();
- TLibraryManager* GetLocalLibraryManager();
- TDynamic* NewObject(const TClassID classID, OSErr*, TStandardPool*);
-
- #ifdef __cplusplus
- extern void* SLMNewOperator(size_t, TMemoryPool*); // no need to call this directly
- extern void SLMDeleteOperator(void*); // no need to call this directly
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- /*******************************************************************************
- ** CLASS TSimpleDynamic
- **
- ** A base class for shared-library classes that has no virtual functions. This
- ** class is NOT shared, since it is intended to be a trivial class that just
- ** forces the VTable to be at the front of the object.
- ********************************************************************************/
-
- #ifdef __cplusplus
-
- class TSimpleDynamic : public SingleObject
- {
- public:
- virtual ~TSimpleDynamic();
-
- void* operator new(size_t size, TMemoryPool*); // from specified pool
- void* operator new(size_t); // from default pool
- void operator delete(void* obj, size_t)
- { SLMDeleteOperator(obj); }
-
- const TClassID& GetObjectsClassID() const;
- const TClassID& GetObjectsParentClassID() const;
- size_t GetObjectsSize() const;
- TLibraryFile* GetObjectsLocalLibraryFile() const;
- TStandardPool* GetObjectsLocalPool() const;
- void SetObjectsLocalPool(TStandardPool*) const;
-
- Boolean IsDerivedFrom(const TClassID&) const;
-
- protected:
- TSimpleDynamic();
-
- private:
- TSimpleDynamic(const TSimpleDynamic&);
- void operator=(const TSimpleDynamic&);
- };
-
- /* -----------------------------------------------------------------
- Inline methods for TSimpleDynamic
- ----------------------------------------------------------------- */
-
- inline void* TSimpleDynamic::operator new(size_t size, TMemoryPool* thePool)
- {
- return SLMNewOperator(size, thePool);
- }
-
- inline void* TSimpleDynamic::operator new(size_t size)
- {
- return SLMNewOperator(size, NULL);
- }
-
- /*******************************************************************************
- ** CLASS TDynamic
- **
- ** The base class for all shared-library classes.
- ********************************************************************************/
-
- #define kTDynamicID "!$dyna"
-
- enum TraceControlType
- {
- kTraceStatus = 1, kTraceOn, kTraceOff
- };
-
- class TDynamic : public SingleObject
- {
- public:
- virtual ~TDynamic();
-
- void* operator new(size_t size, TMemoryPool*); // from specified pool
- void* operator new(size_t); // from default pool
- void operator delete(void* obj, size_t)
- { SLMDeleteOperator(obj); }
-
-
- const TClassID& GetObjectsClassID() const;
- const TClassID& GetObjectsParentClassID() const;
- size_t GetObjectsSize() const;
- TLibraryFile* GetObjectsLocalLibraryFile() const;
- TStandardPool* GetObjectsLocalPool() const;
- void SetObjectsLocalPool(TStandardPool*) const;
-
- virtual Boolean IsValid() const;
-
- virtual OSErr Inflate(TFormattedStream&);
- virtual OSErr Flatten(TFormattedStream&) const;
- virtual TDynamic* Clone(TStandardPool*) const;
-
- virtual char* GetVerboseName(char*) const;
- virtual void Dump() const;
-
- void Trace(char *formatStr, ...) const;
- virtual Boolean TraceControl(TraceControlType) const;
- Boolean IsTraceOn() const;
- Boolean TraceOn() const;
- Boolean TraceOff() const;
-
- Boolean IsDerivedFrom(const TClassID&) const;
-
- protected:
- TDynamic();
-
- private:
- TDynamic(const TDynamic&);
- void operator=(const TDynamic&);
- };
-
- /* -----------------------------------------------------------------
- Inline methods for TDynamic
- ----------------------------------------------------------------- */
-
- inline void* TDynamic::operator new(size_t size, TMemoryPool* thePool)
- {
- return SLMNewOperator(size, thePool);
- }
-
- inline void* TDynamic::operator new(size_t size)
- {
- return SLMNewOperator(size, NULL);
- }
-
- inline Boolean TDynamic::IsTraceOn() const
- {
- return TraceControl(kTraceStatus);
- }
-
- inline Boolean TDynamic::TraceOn() const
- {
- return TraceControl(kTraceOn);
- }
-
- inline Boolean TDynamic::TraceOff() const
- {
- return TraceControl(kTraceOff);
- }
-
- #endif __cplusplus
-
- /*******************************************************************************
- ** Class TClassID
- ********************************************************************************/
-
- #ifdef __cplusplus
-
- const size_t kMaxClassIDSize = 64;
-
- class TClassID : public SingleObject
- {
- public:
- void* operator new(size_t, size_t strLen)
- {
- return SLMNewOperator(
- (sizeof(TClassID) -
- sizeof(char[kMaxClassIDSize]) +
- strLen), NULL);
- }
-
- void operator delete(void* obj, size_t)
- { SLMDeleteOperator(obj); }
-
- TClassID();
- TClassID(const char*);
- TClassID(const TClassID&);
-
- TClassID& operator=(const char*);
- Boolean operator==(const TClassID&) const; // compare with another TClassID
- Boolean operator==(const char*) const; // compare with type string
- short Compare(const char*) const;
-
- private:
- char fClassIDStr[kMaxClassIDSize];
- };
-
- /* -----------------------------------------------------------------
- Inline methods for TClassID
- ----------------------------------------------------------------- */
-
- inline TClassID::TClassID()
- {
- fClassIDStr[0] = 0;
- }
-
- inline TClassID::TClassID(const char* theTypeStr)
- {
- strcpy(fClassIDStr, theTypeStr);
- }
-
- inline TClassID::TClassID(const TClassID& classID)
- {
- strcpy(fClassIDStr, (const char*)&classID);
- }
-
- inline short TClassID::Compare(const char* classIDStr) const
- {
- return (strcmp(classIDStr, fClassIDStr));
- }
-
- inline Boolean TClassID::operator==(const char* classID) const
- {
- return (Compare(classID) == 0);
- }
-
- inline Boolean TClassID::operator==(const TClassID& classID) const
- {
- return (Compare((const char*)&classID) == 0);
- }
-
- inline TClassID& TClassID::operator=(const char* theTypeStr)
- {
- strcpy(fClassIDStr, theTypeStr);
- return *this;
- }
-
- inline const TClassID& ClassID(const char* str)
- {
- return *(const TClassID*)str;
- }
-
- #endif __cplusplus
-
- /*******************************************************************************
- ** Class TLibraryManager
- **
- ** The user's interface to the world!
- ********************************************************************************/
-
- #ifdef __cplusplus
-
- #define kTLibraryManagerID "!$lmgr"
-
- class TLibraryManager : public TDynamic
- {
- private:
- virtual ~TLibraryManager();
- TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
-
- public:
- virtual void Dump() const;
-
- // New Methods
-
- virtual TDynamic* NewObject(const TClassID& classID,
- OSErr* = NULL, TStandardPool* = NULL) const;
- virtual TDynamic* NewObject(const TClassID& classID, const TClassID& baseClassID,
- OSErr* = NULL, TStandardPool* = NULL) const;
- virtual TDynamic* NewObject(const TFormattedStream&,
- OSErr* = NULL, TStandardPool* = NULL) const;
-
- virtual TClassInfo* GetClassInfo(const TClassID& classID, OSErr* err=NULL) const;
- virtual OSErr GetParentClassID(const TClassID& classID, TClassID& parentClassID) const;
-
- virtual OSErr VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
- virtual OSErr VerifyClass(const TDynamic* theObject, const TClassID& baseClassID) const;
-
- virtual Boolean LoadClass(const TClassID& classID, Boolean loadAll = false, OSErr* = NULL) const;
- virtual void UnloadClass(const TClassID& classID) const;
- virtual Boolean IsClassLoaded(const TClassID& classID) const;
-
- void SetObjectPool(TStandardPool*);
- TStandardPool* GetObjectPool() const;
- void SetDefaultPool(TStandardPool*);
- TStandardPool* GetDefaultPool() const;
- Ptr GetGlobalWorld() const;
-
- TLibraryFile* GetLibraryFile() const;
-
- virtual Boolean TraceLogOn();
- virtual Boolean TraceLogOff();
-
- virtual void RegisterDynamicObject(TDynamic*);
- virtual void UnRegisterDynamicObject(TDynamic*);
-
-
- private:
- TLibraryManager(const TLibraryManager&);
- void operator=(const TLibraryManager&);
-
- private:
- TStandardPool* fPool; // pool used for new objects and local pool
- TLibraryFile* fLibraryFile;
- TStandardPool* fDefaultPool;
- Ptr fGlobalWorld;
-
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TLibraryManager
- ----------------------------------------------------------------- */
-
- inline TStandardPool* TLibraryManager::GetObjectPool() const
- {
- return fPool;
- }
-
- inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
- {
- fPool = thePool;
- }
-
- inline TStandardPool* TLibraryManager::GetDefaultPool() const
- {
- return fDefaultPool;
- }
-
- inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
- {
- fDefaultPool = thePool;
- }
-
- inline Ptr TLibraryManager::GetGlobalWorld() const
- {
- return fGlobalWorld;
- }
-
- inline TLibraryFile* TLibraryManager::GetLibraryFile() const
- {
- return fLibraryFile;
- }
-
- /* -------------------------------------------------------------------------
- Inline methods for TDynamic
- ------------------------------------------------------------------------- */
-
- inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
- {
- return (GetLocalLibraryManager()->VerifyClass(this, id) == kNoError);
- }
-
- /* -------------------------------------------------------------------------
- Inline methods for TSimpleDynamic
- ------------------------------------------------------------------------- */
-
- inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
- {
- return ((const TDynamic*)this)->GetObjectsClassID();
- }
-
- inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
- {
- return ((const TDynamic*)this)->GetObjectsParentClassID();
- }
-
- inline size_t TSimpleDynamic::GetObjectsSize() const
- {
- return ((const TDynamic*)this)->GetObjectsSize();
- }
-
- inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
- {
- return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
- }
-
- inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
- {
- return ((const TDynamic*)this)->GetObjectsLocalPool();
- }
-
- inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
- {
- ((const TDynamic*)this)->SetObjectsLocalPool(pool);
- }
-
- inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
- {
- return ((const TDynamic*)this)->IsDerivedFrom(id);
- }
-
- #endif __cplusplus
-
- #endif
-